/*
 * Copyright (C) 2013 The i18nCTS Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.googlecode.i18nCTS.view;

import java.util.Calendar;

import android.text.format.DateUtils;
import android.util.Log;

import com.googlecode.i18nCTS.provider.i18nCTSProvider;
import com.googlecode.i18nCTS.util.i18nCTSUtils;

public class DateUtilsDayWeekdaySectionFragment extends AbstractSectionFragment {
	private static final String TAG = "I18nCTS_" + DateUtilsDayWeekdaySectionFragment.class.getSimpleName();
	public static final String CATEGORY = "DateUtils_Weekday";
	static int flags = 0;

	public DateUtilsDayWeekdaySectionFragment() {
		Log.d(TAG, "ctr");
	}

	 void addDateWeekday(i18nCTSProvider provider, long time1, long time2, int flag) {
		int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY;
		if (flag != 0) flags |= flag;
		
		i18nCTSUtils utils = new i18nCTSUtils(mContext);
		if (time1 == time2) 
			provider.addData(DateUtils.formatDateTime(mContext, time1, flags), utils.getParam(flags));
		else
			provider.addData(DateUtils.formatDateRange(mContext, time1, time2, flags), utils.getParam(flags));
	}	

   void buildWeekday(i18nCTSProvider provider, long time1, long time2) {
    	addDateWeekday(provider, time1, time2, 0);
    	addDateWeekday(provider, time1, time2, DateUtils.FORMAT_SHOW_YEAR);
    	addDateWeekday(provider, time1, time2, DateUtils.FORMAT_NO_YEAR);
    	addDateWeekday(provider, time1, time2, DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NUMERIC_DATE);
    	addDateWeekday(provider, time1, time2, DateUtils.FORMAT_NO_YEAR | DateUtils.FORMAT_NUMERIC_DATE);
    	addDateWeekday(provider, time1, time2, DateUtils.FORMAT_ABBREV_WEEKDAY);
    	addDateWeekday(provider, time1, time2, DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_WEEKDAY);
    	addDateWeekday(provider, time1, time2, DateUtils.FORMAT_NO_YEAR | DateUtils.FORMAT_ABBREV_WEEKDAY);
    	addDateWeekday(provider, time1, time2, DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_ABBREV_WEEKDAY);
    	addDateWeekday(provider, time1, time2, DateUtils.FORMAT_NO_YEAR | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_ABBREV_WEEKDAY);
    }
   
	@Override
	public String getCategory() {
		return CATEGORY;
	}
	
	@Override
	public void buildList(i18nCTSProvider provider) {
    	Calendar cal = Calendar.getInstance();
    	cal.set(2012, 1, 3, 4, 7);
    	Calendar cal2 = Calendar.getInstance();
		buildWeekday(provider, cal.getTimeInMillis(), cal.getTimeInMillis()); 		
		cal2.set(2012, 1, 26, 14, 17);
		buildWeekday(provider, cal.getTimeInMillis(), cal2.getTimeInMillis());        
		cal2.set(2012, 10, 26, 15, 45);
		buildWeekday(provider, cal.getTimeInMillis(), cal2.getTimeInMillis());        				
		cal2.set(2014, 1, 26, 22, 04);
		buildWeekday(provider, cal.getTimeInMillis(), cal2.getTimeInMillis());        				
		cal2.set(2014, 10, 26, 23, 44);
		buildWeekday(provider, cal.getTimeInMillis(), cal2.getTimeInMillis());        

		provider.addTitle(CATEGORY);
	}
}

